<?php

/**
 * Console_Rule Model
 * 
 * Short file description
 *
 * PHP Version: 5.3.26
 * 
 * @category Console_Rule_Models
 * @package  Console_Rule_Package
 * @author   
 * @license  
 * @link     
 */

// namespace and use here

/**
 * Class Console_Rule Model
 * 
 * Class Description
 *
 * @category Console_Rule_Models
 * @package  Console_Rule_Package
 * @author   
 * @license  Laravel License
 * @link     
 */

class Console_Rule extends Eloquent 
{

	public static $timestamps = true;
    public static $table = 'sys_flow_rule';
    public static $key = 'sfr_id';

	/**
     * Function to get Access Control Level for each user
	 * 
	 * @return getAuthorizeState.
     */

	public static function getAuthorizeState(){

		$access = Console_Rule::where('sur_id','=',Auth::user()->sur_id)->get();

		$data = array();

		foreach ($access as $value) {
			array_push($data, $value->sfs_id);
		}

		return $data;

	}

	/**
     * Function to get Access Control Level for each user
	 * 
	 * @return getAuthorizeState.
     */

	public static function getAuthorizeStep(){

		$access = Console_Rule::where('sfr_state','<>', 0)->get(array('sf_id','sfs_id'));

		$data = array();
		$checkUnique = array();

		foreach ($access as $key => $value) {

			$step = Console_Step::where('sfs_id','=',$value->sfs_id)->first();
			
			if($step && !in_array($value->sfs_id, array_values($checkUnique))):
				
				$data[$key]['sf_id'] = $value->sf_id;
				$data[$key]['sfs_id'] = $value->sfs_id;
				$data[$key]['sfs_step'] = $step->sfs_step;

				array_push($checkUnique, $value->sfs_id);

			endif;

			
		}
		
		return $data;

	}


}
